package com.justnow.offer;

import java.util.HashSet;

public class Solution3 {
    public int lengthOfLongestSubstring(String s) {
        HashSet<Character> set = new HashSet<>();
        int left = 0, right = 0, max = 0;
        while (right < s.length()) {
            while (set.contains(s.charAt(right))) {
                set.remove(s.charAt(left));
                left++;
            }
            set.add(s.charAt(right));
            right++;
            max = Math.max(right - left, max);
        }

        return max;
    }

    public static void main(String[] args) {
        Solution3 solution3 = new Solution3();
        String test = "abcdefabcgih";
        int i = solution3.lengthOfLongestSubstring(test);
        System.out.println(i);
    }
}
